package com.silverhaze.diamond.client.ui.dialogs;

import com.silverhaze.commons.utils.RuntimeHelper;
import com.silverhaze.commons.helpers.CommonUIHelper;
import com.silverhaze.diamond.client.ui.UIHelper;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * SystemUser: Babanin
 * Date: 24.07.2008
 * Time: 0:56:30
 */
public class GarbageCollectorDialog extends AbstractDialog {

    public GarbageCollectorDialog() {
        super(UIHelper.getMainFrame());

        long memoryUsedBefore = RuntimeHelper.getUsedMemory();
        long memoryUsedAfter = RuntimeHelper.getUsedMemory();

        setTitle("Оптимизация памяти");

        Box hBox = CommonUIHelper.createHorizontalBox(
                5, "До: ", 1,

                "<html><b>" + Long.toString(memoryUsedBefore) + "</b></html>",

                " мегабайт", 5,
                "После: ",

                "<html><b>" + Long.toString(memoryUsedAfter) + "</b></html>", 

                " мегабайт", 10, new JButton(new AbstractAction("Close") {
            public void actionPerformed(ActionEvent e) {
                okPressed();
            }
        }));

        setResizable(false);

        hBox.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        setLayout(new BorderLayout());
        add(hBox, BorderLayout.CENTER);

        pack();
        setLocationRelativeTo(null);
    }

    protected void okPressed() {
        dispose();
    }

    public static void showDialog() {
        new GarbageCollectorDialog().setVisible(true);
    }
}

